package org.mch.main;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;

import org.mch.start.About;
import org.mch.swingm.event.MBaseEvent;

public class MCHFrameEvent extends MBaseEvent {
	private static final long serialVersionUID = -7984581360488038430L;

	private About about;

	private MCHFrame frame;

	public MCHFrameEvent(MCHFrame frame) {
		super();
		this.frame = frame;
	}

	protected void onButtonClick(ActionEvent e) {
		if (e.getSource() == getFrame().getMntmAbout()) {
			onBoAbout();
		} else if (e.getSource() == getFrame().getMntmExit()) {
			onBoExit();
		}
	}

	private void onBoExit() {
		getFrame().removeAll();
		getFrame().dispose();
	}

	private void onBoAbout() {

		Toolkit kit = Toolkit.getDefaultToolkit(); // 定义工具包
		Dimension screenSize = kit.getScreenSize(); // 获取屏幕的尺寸
		int screenWidth = screenSize.width / 2; // 获取屏幕的宽
		int screenHeight = screenSize.height / 2; // 获取屏幕的高
		int height = getAbout().getHeight();
		int width = getAbout().getWidth();
		// 移动TestFrame至居中位置
		getAbout().setLocation(screenWidth - width / 2, screenHeight - height / 2 - 50);
		getAbout().setVisible(true);
	}

	public MCHFrame getFrame() {
		return frame;
	}

	public About getAbout() {
		if (about == null) {
			about = new About(getFrame());
			about.setModal(true);
		}
		return about;
	}

}
